import React from 'react';
import {connect, Dispatch} from 'umi';
import {ConnectState} from '@/models/connect';
import {Form, Input, Modal} from 'antd';
import {IGrobalFilter} from "@/pages/Analysis/components/GrobalFilter/type";


require("./index.less")

interface IProps {
  dispatch: Dispatch;
  currentEditingItem: IGrobalFilter
  visible: boolean
  onSave: ({column, alias}: any) => void
  onCancel: () => void
}

const FieldConfig: React.FC<IProps> = ({
                                         dispatch,
                                         currentEditingItem,
                                         visible,
                                         onSave,
                                         onCancel,
                                       }) => {

  const [form] = Form.useForm();
  const {column, alias} = currentEditingItem
  return (
    <Modal
      visible={visible}
      title="字段设置"
      okText="保存"
      cancelText="取消"
      onCancel={onCancel}
      onOk={() => {
        form
          .validateFields()
          .then(values => {
            onSave({column: column, alias: values.alias});
          })
      }}
    >
      <Form
        form={form}
        layout="vertical"
        name="form_in_modal"
        initialValues={{modifier: 'public'}}
      >
        <Form.Item
          name="alias"
          label="字段别名"
          initialValue={alias}
        >
          <Input/>
        </Form.Item>
      </Form>
    </Modal>)
};
export default connect(({sheet, dataRole}: ConnectState) => ({
  sheetList: sheet.sheetList
}))(FieldConfig);
